Skip to content

Add URL validation to operational server webhooks #1887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 21, 2025

Conversation

CodeMan62
Copy link
Contributor

Motivation

This PR addresses issue #1138 "Handling of operational webhooks server name" which was identified after users experienced problems configuring and troubleshooting operational webhooks in local development environments.

The current implementation of operational webhooks has two key issues:

  1. The server URL provided in SVIX_OPERATIONAL_WEBHOOK_ADDRESS is not validated or sanitized before use, leading to problems when users provide URLs with trailing slashes or incorrect formats.

  2. When operational webhooks fail to deliver with a 404 error, the system logs a generic "Operational webhooks are enabled but no listener set for {org_id}" message, without distinguishing between different failure scenarios (e.g., incorrect URL format, missing application, or missing endpoint).

These issues make it difficult to diagnose and resolve operational webhook configuration problems, as referenced in discussion #1125 where a user couldn't get operational webhooks working locally.

Solution

This PR implements three key improvements to the operational webhooks handling:

  1. URL Validation: Added validation for the operational_webhook_address configuration value in cfg.rs that verifies:

    • The URL has a valid format
    • The URL uses http or https scheme
    • The URL includes a valid host
  2. URL Sanitization: Enhanced the OperationalWebhookSenderInner::new method in operational_webhooks.rs to properly sanitize URLs by:

    • Trimming whitespace
    • Removing trailing slashes
    • Preserving the essential URL structure
  3. Improved Error Handling: Expanded the error handling in send_operational_webhook to provide more detailed diagnostics:

    • Distinguishes between "no application exists" and "no endpoint configured" scenarios for 404 errors
    • Adds specific handling for BAD_REQUEST errors that often indicate URL format issues
    • Includes the actual URL in error messages to aid debugging

@CodeMan62 CodeMan62 requested a review from a team as a code owner April 15, 2025 19:26
Copy link
Member

@svix-jplatte svix-jplatte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

The URL validation part seems fine to me.

Regarding URL sanitization, see inline comments.

Regarding the error handling,

When operational webhooks fail to deliver with a 404 error, the system logs a generic "Operational webhooks are enabled but no listener set for {org_id}" message, without distinguishing between different failure scenarios (e.g., incorrect URL format, missing application, or missing endpoint).

This does not make sense to me. Incorrect URL format is something we should be catching earlier, so no need to try to distinguish this when receiving a 404. No endpoints for the app does not result in an error at all.

svix-jplatte
svix-jplatte previously approved these changes Apr 21, 2025
@CodeMan62
Copy link
Contributor Author

Thank you @svix-jplatte for all you helps

@svix-jplatte svix-jplatte merged commit 11864b6 into svix:main Apr 21, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants